package com.ak.demo;

import com.ak.demo.trigger.HelloCronTrigger;
import com.ak.demo.trigger.HelloSimpleTrigger;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.util.Date;

public class MyHelloCronTrigger {
    public static void main(String[] args) throws SchedulerException {

        Scheduler scheduler= StdSchedulerFactory.getDefaultScheduler();

        JobDetail jobDetail= JobBuilder.newJob(HelloCronTrigger.class)
                .withIdentity("trigger","group1")
                .build();

        Trigger trigger= TriggerBuilder.newTrigger()
                .withIdentity("trigger","group1")
                // 0 1 0 * * ? 每天 0点1 分开始执行
                // 0/2 * * * * ? 每两秒执行一次
                .withSchedule(CronScheduleBuilder.cronSchedule("0/2 * * * * ?")
                )
                .build();
        scheduler.scheduleJob(jobDetail,trigger);

        scheduler.start();
    }
}
